<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div></div>
    <script>
      const gift = "50g的茶叶,清洗球";
      // 把字符串拆分成数组
      //   console.log(gift.split(","));
      // 字符串的截取
      //   根据数组元素个数 生成对应的span标签
      const str = gift
        .split(",")
        .map(function (item) {
          return `<span>【赠品】${item}</span> <br>`;
        })
        .join("");
      document.querySelector("div").innerHTML = str;
    </script>
  </body>
</html>
